//
//  ARPictureCell.m
//  AriseSamePro
//
//  Created by 包日守 on 15/10/31.
//  Copyright © 2015年 Arise. All rights reserved.
//

#import "ARPictureCell.h"
#import "UIImageView+ARRessume.h"
#import "UIImageView+WebCache.h"
//#import "SDWebImageDownloader.h"

@interface ARPictureCell ()
@property (weak, nonatomic) IBOutlet UIImageView *icomImageView;


@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;


@property (weak, nonatomic) IBOutlet UILabel *contentLabel;

@property (weak, nonatomic) IBOutlet UILabel *likesLabel;
@property (weak, nonatomic) IBOutlet UILabel *viewsLabel;

@property (weak, nonatomic) IBOutlet UIButton *likeButton;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageHightConstraint;

@end


@implementation ARPictureCell

- (IBAction)shareButtonClick:(id)sender {
    
    if (self.ShareBtnBlock) {
        self.ShareBtnBlock(self.cateModel,sender);
    }
}



- (UIButton *) myLikeButton
{
    return self.likeButton;

}

- (void) setCateModel:(ARCate5Model *)cateModel
{
    _cateModel = cateModel;
    
    
   // NSLog(@"%@",self.theMainImageView.ar_progress);
    //self.theMainImageView.ar_progress;
    
    self.icomImageView.clipsToBounds = YES;
    self.icomImageView.layer.cornerRadius = 16;
    
    
    self.icomImageView.image = nil;
    
    //[self.theMainImageView ar_clear];
    
    [self.icomImageView sd_setImageWithURL:[NSURL URLWithString:cateModel.userModel.avatar]];
    //[self.theMainImageView setImageWithURL:[NSURL URLWithString:cateModel.photo]];
    
    //[self.theMainImageView sd_setImageWithURL:[NSURL URLWithString:cateModel.photo]];
    
    [self.theMainImageView ar_setImageWithURL:cateModel.photo];
    /*
    SDWebImageDownloader * sd =[[SDWebImageDownloader alloc] init];
    [sd  downloadImageWithURL:[NSURL URLWithString:cateModel.photo] options:SDWebImageDownloaderProgressiveDownload progress:^(NSInteger receivedSize, NSInteger expectedSize) {
        
        NSLog(@"----%ld/%ld",receivedSize,expectedSize);
        
    } completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
        self.theMainImageView.image = image;
    }];
    */
    
    
    if (cateModel.photo == nil) {
        self.imageHightConstraint.constant = 0;
    }
    else
    {
        self.imageHightConstraint.constant = 380;
    }
    
    
    //[self.theMainImageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    self.nameLabel.text = cateModel.userModel.username;
    self.contentLabel.text = cateModel.txt;
    self.likesLabel.text = cateModel.likes.stringValue;
    self.viewsLabel.text = cateModel.views.stringValue;
    
    
    
    

}


- (IBAction)likeButtonClick:(id)sender {
    [self likeButtonAction];
    
}


- (void)awakeFromNib {
    // Initialization code
    //[self.playButton setImage:[UIImage imageNamed:@"channel_audio_stop@2x"] forState:UIControlStateSelected];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
